<template>
	<div class="toplist">
		<div class="top-one">
			<img :src="data.pc_image_text" alt="" @click="goDetail(list[0])">
		</div>
		<div class="top-other">
			<el-carousel :interval="5000" arrow="always" height="29.5rem" indicator-position="none">
				<el-carousel-item v-for="items in count" :key="items">
					<div v-for="(item, str) in list" v-if="(str-1) >= (items - 1) * 4 && (str-1) < items * 4&&str>0"
						:key="str" class="goods-item" @click="goDetail(item)">
						<div>
							<img :src="item.defaultAlbum" alt="" class="goods-img">
							<div class="goods-info">
								<p class="name">
									{{ item.pName }}
								</p>
								<p class="price">
									￥ {{ item.fSalePrice }}
								</p>
							</div>
						</div>
					</div>
				</el-carousel-item>
			</el-carousel>
		</div>
		
		<div class="more">
			<!-- <img src="../../assets/img/logo2.png" alt="" @click="topList"> -->
		</div>
	</div>
</template>

<script>
	export default {
		name: "",
		components: {},
		props: {
			data: {
				type: Object,
				// 对象或数组默认值必须从一个工厂函数获取
				default: function() {
					return {};
				},
			},
		},
		data() {
			return {
				list: [],
				count: "",
				coverList: [],
				second: {},
			};
		},
		mounted() {
			this.$api.home.getTopList().then((res) => {
				if (res.code == 1) {
					this.coverList = res.data;
				}
			});
			let params = {
				queryCondition: {
					order: [{
						fieldname: "iOrder",
						direction: "asc",
					}, ],
					pageindex: 1,
					pagesize: 16,
					where: [{
						fieldname: "tag_id",
						valuefrom: this.data.connect_id,
					}, ],
				},
			};
			let data = {
				shop_id: ''
			}
			this.$api.home.sales(data).then((res) => {
				if (res.code == 1) {
					this.list = res.data;
					if (res.data.length >= 1) {
						this.count = Math.ceil((res.data.length - 1) / 4);
					} else {
						this.count = 1
					}

				}
			});
		},
		methods: {
			topList() {
				this.$router.push({
					path: "/top"
				});
			},
			//跳转商品详情
			goDetail(item) {
				console.log('跳转商品详情', item)
				if (item === undefined) {
					return
				} else {
					this.$router.push({
						path: "/fruit/detail",
						query: {
							id: item.pid,
							iShopId: item.shop_id
						}
					})
				}
			},
		},
	};
</script>

<style scoped lang="scss">
	.toplist {
		padding: 0 10rem;
		margin-top: 2.19rem;
		display: flex;
		flex-direction: column;

		.top-one {
			width: 100%;
			cursor: pointer;

			img {
				width: 100%;
			}
		}

		.top-other {
			margin-top: 1.25rem;
			margin-bottom: 1.25rem;

			.el-carousel__item {
				display: flex;
				align-items: center;
				justify-content: flex-start;

				.goods-item {
					width: 20.94rem;
					height: 100%;
					background: #fff;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: space-around;
					position: relative;
					margin-right: 1.19rem;
					cursor: pointer;
					text-align: center;

					&:nth-child(4n) {
						margin-right: 0;
					}

					.goods-img {
						width: 15rem;
						height: 15rem;
						object-fit: contain;
					}

					.goods-info {
						display: flex;
						flex-direction: column;
						text-align: center;
						padding: 0 1rem;

						.name {
							font-size: 1.13rem;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: rgba(4, 0, 0, 1);
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							width: 18rem;
							line-height: 1.5;
						}
						.price {
							font-size: 1.5rem;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: rgba(243, 64, 111, 1);
							margin-top: 0.94rem;
						}
					}
				}
			}
		}

		.more {
			height: 2.5rem;
			background: rgba(0, 0, 0, 1);
			display: flex;
			justify-content: flex-end;
			align-items: center;
			padding: 0 1.44rem;

			img {
				width: 7.38rem;
				cursor: pointer;
			}
		}
	}
</style>
